define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'property/index',
                    add_url: 'property/add',
                    edit_url: 'property/edit',
                    del_url: 'property/del',
                    multi_url: 'property/multi',
                    table: 'property',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'property_add_time', title: __('Property_add_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'property_number', title: __('Property_number')},
                        {field: 'property_large_category', title: __('Property_large_category')},
                        {field: 'property_small_category', title: __('Property_small_category')},
                        {field: 'property_name', title: __('Property_name')},
                        {field: 'property_sku', title: __('Property_sku')},
                        {field: 'property_buy_time', title: __('Property_buy_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'property_status', title: __('Property_status'), visible:false, searchList: {"1":__('Property_status 1')}},
                        {field: 'property_status_text', title: __('Property_status'), operate:false},
                        {field: 'property_warehouse', title: __('Property_warehouse')},
                        {field: 'property_last_time', title: __('Property_last_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'property_due_date', title: __('Property_due_date')},
                        {field: 'property_account', title: __('Property_account'), operate:'BETWEEN'},
                        {field: 'property_depreciation', title: __('Property_depreciation')},
                        {field: 'property_residual_value', title: __('Property_residual_value')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});